﻿package mortal.game.view.copy.ChallengeCopy.newView
{
    import Message.DB.Tables.*;
    import mortal.game.cache.*;
    import mortal.game.view.copy.ChallengeCopy.data.*;

    public class ChallengeUtil extends Object
    {

        public function ChallengeUtil()
        {
            return;
        }// end function

        public static function getSectionUrlByTChallenge(param1:TChallengeCopy, param2:String = "png") : String
        {
            var _loc_3:* = param1.tower + "T" + getSectionByTChallenge(param1.section) + "S." + param2;
            return _loc_3;
        }// end function

        public static function getLevelUrlByTChallenge(param1:TChallengeCopy, param2:int) : String
        {
            var _loc_3:* = getLevelUrlByTowerSectionAndLevel(param1.tower, param1.section, param2);
            return _loc_3;
        }// end function

        public static function getLevelUrlByTowerSectionAndLevel(param1:int, param2:int, param3:int) : String
        {
            var _loc_4:* = param1 + "T" + getSectionByTChallenge(param2) + "S" + param3 + "L.png";
            return _loc_4;
        }// end function

        public static function getSectionByTChallenge(param1:int) : int
        {
            return (param1 - 1) % 4 + 1;
        }// end function

        public static function isCanEnterStateByTChallenge(param1:TChallengeCopy, param2:int = 0) : int
        {
            var _loc_5:ChallengeData = null;
            var _loc_6:int = 0;
            var _loc_7:ChallengeData = null;
            var _loc_3:int = -1;
            var _loc_4:* = Cache.instance.role.roleInfo.level;
            if (Cache.instance.role.roleInfo.level >= param1.towerLimitLv)
            {
                _loc_5 = Cache.instance.copy.challengCopy.getDataByTowerAndSection(param1.tower, param1.section);
                _loc_6 = _loc_5.currentSectionMaxLevel;
                if (_loc_5.tChallengCopy.level < _loc_6)
                {
                    if (param1.section == 1)
                    {
                        _loc_3 = 0;
                    }
                    else
                    {
                        _loc_7 = Cache.instance.copy.challengCopy.getDataByTowerAndSection(param1.tower, (param1.section - 1));
                        _loc_6 = _loc_7.currentSectionMaxLevel;
                        if (_loc_7.tChallengCopy.level == _loc_6)
                        {
                            _loc_3 = 0;
                        }
                    }
                    if (param2 > 0 && _loc_3 == 0)
                    {
                        if (param2 - _loc_5.passLevel > 1)
                        {
                            _loc_3 = -1;
                        }
                        else if (param2 - _loc_5.passLevel == 1)
                        {
                            _loc_3 = 0;
                        }
                        else
                        {
                            _loc_3 = 1;
                        }
                    }
                }
                else
                {
                    _loc_3 = 1;
                }
            }
            return _loc_3;
        }// end function

    }
}
